package com.jifeng.br.pjj.bookreader.controller.api;

import com.jifeng.br.pjj.bookreader.entity.BookCommentEntity;
import com.jifeng.br.pjj.bookreader.service.BookCommentService;
import com.jifeng.br.pjj.bookreader.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author PangJunjie
 * @Date 2023/7/19/019
 */
@RestController
@RequestMapping("/api/comment")
public class CommentApiController {
    @Autowired
    private BookCommentService commentService;

    @PostMapping("/save")
    public R save(@RequestBody BookCommentEntity comment) {
        commentService.saveComment(comment);
        return R.ok();
    }

    @GetMapping("/page")
    public R pageByBook(int page, int limit, BookCommentEntity comment) {
        return R.data(commentService.getPage(page, limit, comment));
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable int id) {
        commentService.removeById(id);
        return R.ok();
    }
}
